package com.spring.gop.proj.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

import com.spring.gop.proj.interfaces.FaqService;
import com.spring.gop.proj.model.Faq;

@Controller
@RequestMapping("/help/faq/*")
@SessionAttributes("faq")
public class FaqController {

	@Autowired private FaqService faqService;
	
	@RequestMapping(value="/help/faq/list")
	public void list(Model model) {
		model.addAttribute("pageIdx", 6);
		model.addAttribute("faqt", faqService.selectFaqt());
	}
	
	@RequestMapping(value="/help/faq/userlist")
	public void userlist(Model model){
		model.addAttribute("pageIdx", 6);
		model.addAttribute("faqu", faqService.selectFaqu());
	}
	
	@RequestMapping(value="/help/faq/pointlist")
	public void pointlist(Model model) {
		model.addAttribute("pageIdx", 6);
		model.addAttribute("faqp", faqService.selectFaqp());
	}
	
	@RequestMapping(value="/help/faq/cardlist")
	public void cardlist(Model model) {
		model.addAttribute("faqc", faqService.selectFaqc());
	}
	
	@RequestMapping(value="/help/faq/etclist")
	public void etclist(Model model) {
		model.addAttribute("pageIdx", 6);
		model.addAttribute("faqe", faqService.selectFaqe());
	}
	
	@RequestMapping(value="/help/faq/admin")
	public void admin(Model model){
		model.addAttribute("faqs", faqService.selectFaqs());
	}
	
	@RequestMapping(value="/read", method=RequestMethod.GET)
	public Faq read(int num) {
		return faqService.selectFaq(num);
	}
	
	@RequestMapping(value="/write", method=RequestMethod.GET)
	public void writeForm() {}
	
	@RequestMapping(value="/write", method=RequestMethod.POST)
	public String write(Faq faq, SessionStatus session) {
		faqService.insertFaq(faq);
		session.setComplete();
		return "redirect:admin";
	}
	
	@RequestMapping(value="update", method=RequestMethod.GET)
	public void updateForm() {
	}
	
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public String update(Faq faq,SessionStatus session) {
		faqService.updateFaq(faq);
		session.setComplete();
		return "redirect:admin";
	}
	
	@RequestMapping
	public String del(int num, SessionStatus session){
		faqService.delFaq(num);
		session.setComplete();
		return "redirect:admin";
	}
}
